<template>
  <!--   简历诊断入口页面   -->
  <view>
    <JudgeResultGetData v-show="diagnoseStatus == -1" />
    <JudgeResultInfo v-show="diagnoseStatus == 2" :recordId="recordId" :resultInfo="resultInfo"
      :fromZhituCard="fromZhituCard" @refreshDiagnosisData="refreshDiagnosisData" />
    <JudgeResultFail v-show="diagnoseStatus == 3" :recordId="recordId" :fromZhituCard="fromZhituCard" />
    <JudgeResultDoing v-show="diagnoseStatus == 1" @clickRefresh="handleRefresh" />
  </view>
</template>

<script>
import JudgeResultDoing from "./components/JudgeResultDoing.vue";
import JudgeResultFail from "./components/JudgeResultFail.vue";
import JudgeResultInfo from "./components/JudgeResultInfo.vue";
import JudgeResultGetData from "./components/JudgeResultGetData.vue";

import { getResumeDiagnoseResult, addOrderAndPay } from "@/api/index";
import { getResumeDiagnoseRecord } from "@/api/index";
export default {
  components: {
    JudgeResultDoing,
    JudgeResultFail,
    JudgeResultInfo,
    JudgeResultGetData,
  },

  onLoad: function (option) {
    this.recordId = option.diagnoseRecordId;
    this.fromZhituCard = !!option.fromZhituCard;
    console.log("fromZhituCard", this.fromZhituCard);

    //this.recordId = 25;
  },

  watch: {
    recordId: {
      handler(val) {
        this.getCurrentStatus();
      },
      deep: true, // 深度监听
      immediate: false, // 初始化的时候立刻执行一次
    },
  },

  data() {
    return {
      diagnoseStatus: -1,
      recordId: -1,
      fromZhituCard: false,
      resultInfo: {},
    };
  },

  methods: {
    handleRefresh() {
      this.getCurrentStatus();
    },

    // 获取简历评定信息
    refreshDiagnosisData(res) {
      uni.showLoading();
      let param = {
        diagnoseRecordId: this.recordId,
      };
      // console.log(param);
      getResumeDiagnoseResult(param).then((res) => {
        // console.log(res);
        uni.hideLoading();
        if (res.code == 200) {
          this.resultInfo = res.data;
          uni.setNavigationBarColor({
            frontColor: "#ffffff",
            backgroundColor: "#ffffff",
          });
        } else {
          uni.showToast({
            title: res.status_desc,
            icon: "none",
          });
        }
      });
    },

    //获取当前状态
    getCurrentStatus() {
      this.diagnoseStatus = -1;
      uni.showLoading();
      let param = {
        diagnoseRecordId: this.recordId,
      };
      getResumeDiagnoseRecord(param).then((res) => {
        uni.hideLoading();
        if (res.code == 200) {
          //0:未评定 1:评定中 2：已评定 3：评定失败
          let status = res.data.diagnoseStatus;
          if (status == 0) {
            this.diagnoseStatus = 1;
          } else {
            this.diagnoseStatus = status;
          }
          if (status == 2) {
            this.refreshDiagnosisData({});
          }
        } else {
          uni.showToast({
            title: res.status_desc,
            icon: "none",
          });
        }
      });
    },
  },
};
</script>
<style  lang="scss" scoped>
</style>